package com.company.cloud.common.bean;

import java.util.HashMap;
import java.util.Map;

import com.company.cloud.common.constant.BaseReturnEnum;

import lombok.Getter;
import lombok.Setter;

/**
 * 返回结果
 */
@Getter
@Setter
public class BaseResult {

private static final long serialVersionUID = 1L;
	
	private String code;
	
	private String msg;
	
	private Object data;
//	records
	
	public BaseResult() {
		
	}
	
	public static BaseResult error() {
		return error(BaseReturnEnum.SYSTEM_ERROR.getCode(), BaseReturnEnum.SYSTEM_ERROR.getMsg(), null);
	}
	
	public static BaseResult error(String msg) {
		return error(BaseReturnEnum.SYSTEM_ERROR.getCode(), msg, null);
	}
	
	public static BaseResult error(String code, String msg) {
		return error(code, msg, null);
	}
	
	public static BaseResult error(String code, String msg, Object data) {
//		String lang= AuthContextUtils.getLang();
//		System.out.println("++++++"+lang);
		BaseResult result = new BaseResult();
		result.setCode(code);
		result.setMsg(msg);
		result.setData(data);
		return result;
	}

	public static BaseResult ok() {
//		String lang= AuthContextUtils.getLang();
//		System.out.println("++++++"+lang);
		return ok(null);
	}
	
	public static BaseResult ok(Object data) {
		BaseResult result = new BaseResult();
		result.setCode(BaseReturnEnum.SUCCESS.getCode());
		result.setMsg(BaseReturnEnum.SUCCESS.getMsg());
		result.setData(data);
		return result;
	}

	public  static BaseResult ok(Map<String, Object> data) {
		BaseResult result = new BaseResult();
		result.setCode(BaseReturnEnum.SUCCESS.getCode());
		result.setMsg(BaseReturnEnum.SUCCESS.getMsg());
		result.setData(data);
		return result;
	}
	
	
	public  static BaseResult ok(String key,Object val) {
		Map<String, Object> data=new HashMap<String, Object>();
		data.put(key, val);
		BaseResult result = new BaseResult();
		result.setCode(BaseReturnEnum.SUCCESS.getCode());
		result.setMsg(BaseReturnEnum.SUCCESS.getMsg());
		result.setData(data);
		return result;
	}
	
	
}
